//
//  ZZAESTool.m
//  jtpayTransactionInquiries
//
//  Created by dyj on 16/7/26.
//  Copyright © 2016年 Tangshan Jun-ho Technology Co.Ltd. All rights reserved.
//

#import "ZZAESTool.h"
#import "NSData+AES.h"
#import "NSData+Base64.h"
#import "ConfigureHeader.h"
 NSString  *key = AES_KEY;
 NSString  *iv1 = AES_IV;
@implementation ZZAESTool
- (NSString *)AESencodeWithDic:(id )aesStr{
//    NSError *error =nil;
    NSData *jsonData =[aesStr dataUsingEncoding:NSUTF8StringEncoding];
    NSString * jsonStr = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSData * endData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSData *en_data1 = [endData AES256EncryptWithKey:key iv:iv1];
    NSString *base64=[[en_data1 base64EncodedString] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet controlCharacterSet]];
//    NSString *paraAES256 = [base64 stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
    
    return base64;
    
}
- (NSString *)AESDecodeWithObject:(id)deStr{
    NSData *SecData=[NSData dataFromBase64String:deStr];
    NSData *de_data = [SecData AES256DecryptWithKey:key iv:iv1];
//    NSObject *deObject= [NSJSONSerialization JSONObjectWithData:de_data options:NSJSONReadingMutableLeaves error:&error];
    NSString *destr= [[NSString alloc]initWithData:de_data encoding:NSUTF8StringEncoding];
    return destr;
}
@end
